import React, {
	Component
} from "react";
import {
	View,
	Text,
	ListView,
	TouchableOpacity,
	Image
} from "react-native";
import {
	observer
} from "mobx-react";
import {
	StackNavigator
} from "react-navigation";
import SearchData from "../models/SearchData";
import PropertyView from "./PropertyView";
import styles from "./style";

@observer
class SearchResult extends Component {
	static navigationOptions = {
		title: '热门房子',
	}
	constructor(props) {
		super(props);
		const ds = new ListView.DataSource({
			rowHasChanged: (r1, r2) => r1 !== r2
		});
		this.state = {
			dataSource: ds.cloneWithRows(SearchData.searchString.result.slice())
		};
		this.renderRows = this.renderRows.bind(this);
		this.handlePress = this.handlePress.bind(this);
	}
	handlePress(rowData) {
		const {
			navigate
		} = this.props.navigation;
		navigate("DetailsOfHouse", {
			houseInfo: rowData
		});

	}
	renderRows(rowData, sectionID, rowID) {
		console.log(rowData);
		return (
			<TouchableOpacity onPress={() => {this.handlePress(rowData)}}>
			<View style={styles.ListText}>
				<Image style={styles.images} source={{uri: rowData.img_url}} />
				<View style={styles.rightText}>
					<Text 
						style={styles.rightTitle1}
					>
						{rowData.price_formatted}
					</Text>
					<Text style={styles.rightTitle2}
						numberOfLines={1}
					>
						{rowData.title}
					</Text>
				</View>
			</View>
		</TouchableOpacity>
		);
	}
	render() {
		return (
			<View style={{flex: 1}}>
			<ListView
				dataSource={this.state.dataSource}
				renderRow={this.renderRows}
			/>
			</View>
		);
	}
}

function handle(a) {
	console.log(a)
}

export default SearchResult;